package com.anli02.RabbitMQConfig;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;

import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.retry.MessageRecoverer;
import org.springframework.amqp.rabbit.retry.RepublishMessageRecoverer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ExchageMQ {
    @Bean
    public DirectExchange directExchage()
    {
        return new DirectExchange("erro.direct");


    }
    @Bean
   public Queue erroqueue()
    {
        return new Queue("erro.queue",true);
    }
    @Bean
    public Binding bindingQueue(Queue erroqueue , DirectExchange  directExchage  )
    {
        return BindingBuilder.bind(erroqueue).to(directExchage).with("erro.key");
    }
    @Bean
    public MessageRecoverer messageRecoverer(RabbitTemplate rabbitTemplate)
    {
        return new RepublishMessageRecoverer(rabbitTemplate,"erro.direct","erro.key");
    }


}
